package com.asohofrucol.web;

import java.util.List;

import javax.faces.event.ActionEvent;

import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.springframework.beans.factory.annotation.Autowired;

import com.asohofrucol.dto.AsohofrucolSessionDTO;
import com.asohofrucol.dto.RuatRegisterDTO;
import com.asohofrucol.service.UserOwnerService;

public class SearchOwnerController {
	@Autowired
	private AsohofrucolSessionDTO aSession;

	@Autowired
	private UserOwnerService userOwnerService;

	@Autowired
	private RuatDataController ruatDataController;

	private LazyDataModel<RuatRegisterDTO> lazyRuatRegisterDataModel = new LazyRuatRegisterDataModel();

	public void findRuatDtoListByParamas(ActionEvent actionEvent) {
		System.out.println("findRuatDtoListByParamas");
		Long idType = aSession.getSelectedRuatRegister().getIdType();
		String idNumber = aSession.getSelectedRuatRegister().getIdNumber();
		String name = aSession.getSelectedRuatRegister().getFirstName();
		List<RuatRegisterDTO> ruatRegisters = userOwnerService
				.findRuatDtoListByParamas(idType, idNumber, name);
		aSession.getRuat().setRuatRegisters(ruatRegisters);
	}

	public void onRegisterSelect(SelectEvent event) {
		aSession.setSelectedRuatRegister((RuatRegisterDTO) event.getObject());
	}

	public LazyDataModel<RuatRegisterDTO> getLazyRuatRegisterDataModel() {
		return lazyRuatRegisterDataModel;
	}

	public void setLazyRuatRegisterDataModel(
			LazyDataModel<RuatRegisterDTO> lazyRuatRegisterDataModel) {
		this.lazyRuatRegisterDataModel = lazyRuatRegisterDataModel;
	}

}
